<?php
/**
 * Manages rules for an item
 * 
 */
class KommunController extends Controller {

    /*
     * Browse for county
     */
    public function browse(){
        $listCountyPage = $this->model->listCountyPage();
        $this->set('listCountyPage', $listCountyPage);
        $this->view->setPageTitle('Lista Län');
    }

    /*
     * Browse for municipality
     */
    public function listed(){
        $id = $this->query[0];
        // check so that id is set
        if($id){
             // identifier as int or string?
            if(is_numeric($id))
                $listMuniPage = $this->model->listMuniPage_numeric($id);
            else
                $listMuniPage = $this->model->listMuniPage_string($id);

            $this->set('listMuniPage',$listMuniPage);
            $this->view->setPageTitle($listMuniPage[0]['county_name']);
        }
        else {
            return false;
        }
    }

    public function show(){
        $id = $this->query[0];
        $page = $this->query[1];

        // check so that id is set
        if($id){
            if(is_numeric($id)) // identifier as int or string?
                $readMuniPage = $this->model->readMuniPage_numeric($id);
            else
                $readMuniPage = $this->model->readMuniPage_string($id);

            $fb = new Facebook();
            $fb->setMetaData('og:title', 'Klimatsmart -'.$readMuniPage[0]['muni_name']);
            $fb->setMetaData('og:type', 'website');
            //$fb->setMetaData('og:url', 'www.aftonbladet.se');
            $fb->setMetaData('og:image', 'http://klimatsmartmvc.presis.se/img/presis.gif');
            $fb->setMetaData('og:description', 'Detta är ett test facebooksharing');

            $this->set('facebookData',$fb->getMetaData());
            $this->set('readMuniPage',$readMuniPage[0]);
            $this->view->setPageTitle($readMuniPage[0]['muni_name']);
            $this->set('page',$page);
        }
        else {
            return false;
        }
    }

    public function news(){
        // get first parameter of query array
        $id = $this->query[0];

        // check so that id is set
        if($id){
            if(is_numeric($id)) // identifier as int or string?
                $readMuniPage = $this->model->readMuniPage_numeric($id);
            else
                $readMuniPage = $this->model->readMuniPage_string($id);

            $muniNews = $this->model->searchMuniNews($readMuniPage[0]['muni_name']);

            $this->set('readMuniPage',$readMuniPage[0]);
            $this->set('muniNews', $muniNews);
            $this->view->setPageTitle($readMuniPage[0]['muni_name'].' - Nyheter');
        }
        else {
            return false;
        }
    }


}
?>
